package com.chixing.service.impl;

import com.chixing.mapper.CustomerMapper;
import com.chixing.pojo.Customer;
import com.chixing.pojo.CustomerExample;
import com.chixing.service.CustomerService;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;
    @Override
    public Customer login(Long custTel, String custPassword) {
        CustomerExample example = new CustomerExample();
        example.createCriteria().andCustTelEqualTo(custTel).andCustPasswordEqualTo(custPassword);
      List<Customer> customer = customerMapper.selectByExample(example);
      Customer customer1 = customer.get(0);
      if(custTel.equals(customer1.getCustTel())&&custPassword.equals(customer1.getCustPassword())){
return customer1;
      }
      return null;
    }

    @Override
    public Customer updateCustomer(Integer custId,
                                         String custName,
                                         String custGender,
                                         String custIdCard,
                                         Date custDriverStartTime,
                                         Date custDriverEndTime,
                                         String custDriverType) {
        Customer customer = customerMapper.selectByPrimaryKey(custId);
        customer.setCustName(custName);
        customer.setCustGender(custGender);
        customer.setCustIdCard(custIdCard);
        customer.setCustDriverStartTime(custDriverStartTime);
        customer.setCustDriverEndTime(custDriverEndTime);
        customer.setCustDriverType(custDriverType);
        customer.setCustRegisterTime(new Date());
        customer.setStatus(0);
        customerMapper.updateByPrimaryKey(customer);
        return customer;
    }
}
